package com.auction.controller;

import com.auction.common.core.controller.MyBaseController;
import com.auction.common.utils.ReturnResult;
import com.auction.entity.TransactionLog;
import com.auction.entity.Wallet;
import com.auction.service.WalletService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api")
@Api(tags = "钱包接口")
public class WalletController extends MyBaseController {

    @Autowired
    private WalletService walletService;

    @PostMapping("/save")
    @ApiOperation("添加账户")
    public ReturnResult save(@RequestBody Wallet wallet) {
        int res = walletService.saveEntity(wallet);
        return saveResult(res);
    }

    @PostMapping("/increase")
    @ApiOperation("更新账户金额")
    public ReturnResult increase(@RequestBody TransactionLog transactionLog) {
        int res = walletService.updateWallet(transactionLog);
        return updateResult(res);
    }

    @GetMapping("/getWallet")
    @ApiOperation("查找账户信息")
    public ReturnResult getWallet(int user_id) {
        Map info = walletService.getWalletByUserId(user_id);
        return success("账户信息",info);
    }
}
